import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'chapter2/index.dart';
import 'chapter3/index.dart';
import 'chapter4/index.dart';
import 'chapter5/index.dart';
import 'chapter6/index.dart';
class Routes {
  static List<Map<String, dynamic>> routesList = [
    {
      'title': 'counter计数器',
      'route': '/chapter2/counter',
      'handler': Handler(handlerFunc: (_, __) => const CounterPage())
    },
    {
      'title': 'state管理',
      'route': '/chapter2/state',
      'handler': Handler(handlerFunc: (_, __) => const StatePage())
    },
    {
      'title': '路由传参',
      'route': '/chapter2/route',
      'handler': Handler(handlerFunc: (_, __) => const RouterTestRoute())
    },
    {
      'title': '按钮',
      'route': '/chapter3/buttons',
      'handler': Handler(handlerFunc: (_, __) => const ButtonRoute())
    },
    {
      'title': '表单',
      'route': '/chapter3/form',
      'handler': Handler(handlerFunc: (_, __) => const FormTestRoute())
    },
    {
      'title': '图片和icon',
      'route': '/chapter3/image_icon',
      'handler': Handler(handlerFunc: (_, __) => const ImageIconRoute())
    },
    {
      'title': '字体图标',
      'route': '/chapter3/iconfont',
      'handler': Handler(handlerFunc: (_, __) => const IconFontRoute())
    },
    {
      'title': '自定义进度条',
      'route': '/chapter3/progress',
      'handler': Handler(handlerFunc: (_, __) => const ProgressRoute())
    },
    {
      'title': 'switch_checkbox',
      'route': '/chapter3/switch_checkbox',
      'handler': Handler(handlerFunc: (_, __) => const SwitchAndCheckBoxRoute())
    },
    {
      'title': 'text输入框',
      "route": '/chapter3/textfield',
      'handler': Handler(handlerFunc: (_, __) => const TextFieldRoute())
    },
    {
      'title': 'afterlayout生命周期',
      'route': '/chapter4/afterlayout',
      'handler': Handler(handlerFunc: (_, __) => const AfterLayoutRoute())
    },
    {
      'title': 'table表格',
      'route': '/chapter4/table',
      'handler': Handler(handlerFunc: (_, __) => const TableRoute())
    },
    {
      'title': 'align对齐方式',
      'route': '/chapter4/algin',
      'handler': Handler(handlerFunc: (_, __) => const AlignRoute())
    },
    {
      'title': '约束',
      'route': '/chapter4/constraints',
      'handler': Handler(handlerFunc: (_, __) => const SizeConstraintsRoute())
    },
    {
      'title': '动态创建layout',
      'route': '/chapter4/layoutbuilder',
      'handler': Handler(handlerFunc: (_, __) => const LayoutBuilderRoute())
    },
    {
      'title': 'row-column布局',
      'route': '/chapter4/rowcolumn',
      'handler': Handler(handlerFunc: (_, __) => const RowColumnRoute())
    },
    {
      'title': 'stack布局',
      'route': '/chapter4/stack',
      'handler': Handler(handlerFunc: (_, __) => const StackRoute())
    },
    {
      'title': 'wrap_flow布局',
      'route': '/chapter4/wrap_flow',
      'handler': Handler(handlerFunc: (_, __) => const WrapFlowRoute())
    },
    {
      'title': 'clip裁剪',
      'route': '/chapter5/clip',
      'handler': Handler(handlerFunc: (_, __) => const ClipRoute())
    },
    {
      'title': 'cotnainer布局',
      'route': '/chapter5/container',
      'handler': Handler(handlerFunc: (_, __) => const ContainerRoute())
    },
    {
      'title': 'decoratedbox布局',
      'route': '/chapter5/decoratedbox',
      'handler': Handler(handlerFunc: (_, __) => const DecoratedboxRoute())
    },
    {
      'title': 'filltedBox',
      'route': '/chapter5/filltedBox',
      'handler': Handler(handlerFunc: (_, __) => const FilltedboxRoute())
    },
    {
      'title': 'padding布局',
      'route': '/chapter5/padding',
      'handler': Handler(handlerFunc: (_, __) => const PaddingRoute())
    },
    {
      'title': 'scaffold',
      'route': '/chapter5/scaffold',
      'handler': Handler(handlerFunc: (_, __) => const ScaffoldRoute())
    },
    {
      'title': 'animateList',
      'route': '/chapter6/animateList',
      'handler': Handler(handlerFunc: (_, __) => const AnimateList())
    },
    // configuration
    {
      'title': 'configuration',
      'route': '/chapter5/configuration',
      'handler': Handler(handlerFunc: (_, __) => const ScrollViewConfiguration())
    }
  ];

  static FluroRouter router = FluroRouter();
  // 初始化，配置路由表
  static _initRouter() {
    for (int i = 0; i < routesList.length; i++) {
      router.define(routesList[i]['route'], handler: routesList[i]['handler']);
    }
  }

  // 配置路由
  static void configureRoutes() {
    router.notFoundHandler = Handler(handlerFunc: (_, __) {
      // 找不到路由时，返回404页面
      return Scaffold(
          appBar: AppBar(),
          // 这是自行封装的Empty组件
          body: const Center(child: Text('空页面')));
    });
    // 初始化路由信息
    _initRouter();
  }
}
